package org.testis.guiappsmodule.services;

import org.testis.data.TestStepException;
import org.testis.data.TestStepResultType;
import org.testis.guiappsmodule.data.GuiAppsModuleDataObject;
import org.testis.logging.AtofLogLevel;
import org.testis.logging.LogSenderService;
import org.testis.services.AtofModuleAction;
import org.testis.services.AtofModuleService;
import org.testis.utils.StringVerification;


/**
 *
 * @author nurhat
 */
public class GuiAppsOutputVerificationAction extends AtofModuleAction
{

    @Override
    public boolean operateRequest(AtofModuleService request)
    {
        GuiAppsModuleDataObject dataObj =
            (GuiAppsModuleDataObject) request.getDataObj();
        String expectedOutput = dataObj.getContainsString();
        if (expectedOutput == null) {
            throw new TestStepException(TestStepResultType.MISTAKE,
                                        "Expected  contain string parameter should not be null...");

        }
        boolean result =
            StringVerification.verifyText(expectedOutput,
                                          dataObj.getOutputString());
        if (result) {
            LogSenderService.putMessageOnQueue(
                "GuiAppOutputVerificationAction",
                AtofLogLevel.INFO,
                "Output contains provided string " + expectedOutput,
                dataObj.getMessageId());
            return true;
        }
        else {
            result =
                StringVerification.verifyText(expectedOutput,
                                              dataObj.getErrorString());
            if (result) {
                LogSenderService.putMessageOnQueue(
                    "GuiAppOutputVerificationAction",
                    AtofLogLevel.ERROR,
                    "Error output contains provided string " + expectedOutput,
                    dataObj.getMessageId());
                return true;
            }
        }
        LogSenderService.putMessageOnQueue(
            "GuiAppOutputVerificationAction",
            AtofLogLevel.ERROR,
            "Output does not contain provided string " + expectedOutput,
            dataObj.getMessageId());
        return false;
    }
}

